package com.changgou.comment.controller;

import com.changgou.comment.feign.CommentFeign;
import com.changgou.order.feign.OrderFeign;
import com.changgou.order.pojo.OrderItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuzhouwei
 * @date 2020/5/31
 */
@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentFeign commentFeign;

    @Autowired
    private OrderFeign orderFeign;

    /**
     * 根据登录的用户名, 查询并展示已收到货,未评价的商品
     * 需要修改数据库的订单表的consign_status数据
     * @param model
     * @return
     */
    @GetMapping("/list")
    public String list( Model model){
        String username = "szitheima";
        String image=null;
        String orderId1=null;
        String name=null;
        Integer num=null;
        Integer price=null;
        Integer money=null;
        Long skuId=null;
        List<List<OrderItem>> orderItems = orderFeign.findCommentGoodsByOrderIdAndUsername();
        //TODO 这里应该是直接传orderItems到  评价页面,  让页面循环展示未评价的商品
        for (List<OrderItem> orderItem : orderItems) {
            for (OrderItem item : orderItem) {
                image = item.getImage();
                orderId1 = item.getOrderId();
                name = item.getName();
                num = item.getNum();
                price = item.getPrice();
                money = item.getMoney();
                skuId = item.getSkuId();
            }
        }
        Map map = new HashMap();
        map.put("image",image);
        map.put("orderId1",orderId1);
        map.put("name",name);
        map.put("num",num);
        map.put("price",price);
        map.put("money",money);
        model.addAttribute("resultMap",map);
        return "mycomment";
    }

}
